//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include "PatternRecord.h"
#include "Pratt2Patterns.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <fstream>
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#define LENGTHTEXT 10000
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
Pratt2Patterns::Pratt2Patterns () {
  
  this->namefile  = new String ();

  this->code      = 0;
  this->numberSeq = 0;

  this->cM        = 0;
  this->cPercent  = 0.0;

  this->pP        = new String ();
  this->pL        = 0;
  this->pN        = 0;
  this->pX        = 0;
  this->fN        = 0;
  this->fL        = 0;
  this->fP        = 0;
  this->bI        = false;
  this->bN        = 0;

  this->s         = new String ();

  this->g         = new String ();
  this->e         = 0;
  this->r         = true;
  this->rG        = true;

  this->oF        = new String ();
  this->oP        = true;
  this->oN        = 0;
  this->oA        = 0;
  this->m         = true;
  this->mR        = 0;
  this->mV        = false;

  this->patterns  = new TListE <PatternRecord> ();
  this->matches   = new TListE <PatternMatches> ();

  this->toString  = new String ();
    
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
Pratt2Patterns::Pratt2Patterns (const Pratt2Patterns& pratt2Patterns) {
  
  this->namefile  = new String (pratt2Patterns.namefile);

  this->code      = pratt2Patterns.code;
  this->numberSeq = pratt2Patterns.numberSeq;

  this->cM        = pratt2Patterns.cM;
  this->cPercent  = pratt2Patterns.cPercent;

  this->pP        = new String (pratt2Patterns.pP);
  this->pL        = pratt2Patterns.pL;
  this->pN        = pratt2Patterns.pN;
  this->pX        = pratt2Patterns.pX;
  this->fN        = pratt2Patterns.fN;
  this->fL        = pratt2Patterns.fL;
  this->fP        = pratt2Patterns.fP;
  this->bI        = pratt2Patterns.bI;
  this->bN        = pratt2Patterns.bN;

  this->s         = new String (pratt2Patterns.s);

  this->g         = new String (pratt2Patterns.g);
  this->e         = pratt2Patterns.e;
  this->r         = pratt2Patterns.r;
  this->rG        = pratt2Patterns.rG;

  this->oF        = new String (pratt2Patterns.oF);
  this->oP        = pratt2Patterns.oP;
  this->oN        = pratt2Patterns.oN;
  this->oA        = pratt2Patterns.oA;
  this->m         = pratt2Patterns.m;
  this->mR        = pratt2Patterns.mR;
  this->mV        = pratt2Patterns.mV;

  this->patterns  = new TListE <PatternRecord> (pratt2Patterns.patterns);
  this->matches   = new TListE <PatternMatches> (pratt2Patterns.matches);

  this->toString  = new String ();
    
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
Pratt2Patterns::Pratt2Patterns (const Pratt2Patterns* pratt2Patterns) {
  
  this->namefile  = new String (pratt2Patterns->namefile);

  this->code      = pratt2Patterns->code;
  this->numberSeq = pratt2Patterns->numberSeq;

  this->cM        = pratt2Patterns->cM;
  this->cPercent  = pratt2Patterns->cPercent;

  this->pP        = new String (pratt2Patterns->pP);
  this->pL        = pratt2Patterns->pL;
  this->pN        = pratt2Patterns->pN;
  this->pX        = pratt2Patterns->pX;
  this->fN        = pratt2Patterns->fN;
  this->fL        = pratt2Patterns->fL;
  this->fP        = pratt2Patterns->fP;
  this->bI        = pratt2Patterns->bI;
  this->bN        = pratt2Patterns->bN;

  this->s         = new String (pratt2Patterns->s);

  this->g         = new String (pratt2Patterns->g);
  this->e         = pratt2Patterns->e;
  this->r         = pratt2Patterns->r;
  this->rG        = pratt2Patterns->rG;

  this->oF        = new String (pratt2Patterns->oF);
  this->oP        = pratt2Patterns->oP;
  this->oN        = pratt2Patterns->oN;
  this->oA        = pratt2Patterns->oA;
  this->m         = pratt2Patterns->m;
  this->mR        = pratt2Patterns->mR;
  this->mV        = pratt2Patterns->mV;

  this->patterns  = new TListE <PatternRecord> (pratt2Patterns->patterns);
  this->matches   = new TListE <PatternMatches> (pratt2Patterns->matches);

  this->toString  = new String ();
    
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
Pratt2Patterns::~Pratt2Patterns () {
  
  if (this->namefile) delete this->namefile;
  if (this->pP)       delete this->pP;
  if (this->s)        delete this->s;
  if (this->g)        delete this->g;
  if (this->oF)       delete this->oF;
  if (this->patterns) delete this->patterns;
  if (this->matches)  delete this->matches;
  if (this->toString) delete this->toString;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::Namefile (String* namefile) {
  
  if (namefile) this->namefile->In(namefile);
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::Code (int code) {
  
  this->code = code;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::NumberSeq (int numberSeq) {
  
  if (numberSeq > 0) this->numberSeq = numberSeq;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::CM (int cM) {
  
  if (cM > 0) this->cM = cM;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::CPercent (double cPercent) {
  
  if (cPercent > 0) this->cPercent = cPercent;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::PP (String* pP) {
  
  if (pP) this->pP->In(pP);
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::PL (int pL) {
  
  if (pL > 0) this->pL = pL;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::PN (int pN) {
  
  if (pN > 0) this->pN = pN;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::PX (int pX) {
  
  if (pX > 0) this->pX = pX;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::FN (int fN) {
  
  if (fN > 0) this->fN = fN;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::FL (int fL) {
  
  if (fL > 0) this->fL = fL;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::FP (int fP) {
  
  if (fP > 0) this->fP = fP;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::BI (bool bI) {
  
  this->bI = bI;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::BN (int bN) {
  
  if (bN > 0) this->bN = bN;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::S (String* s) {
  
  if (s) this->s->In(s);
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::G (String* g) {
  
  if (g) this->g->In(g);
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::E (int e) {
  
  if (e > 0) this->e = e;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::R (bool r) {
  
  this->r = r;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::RG (bool rG) {
  
  this->rG = rG;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::OF (String* oF) {
  
  if (oF) this->oF->In(oF);
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::OP (bool oP) {
  
  this->oP = oP;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::ON (int oN) {
  
  if (oN > 0) this->oN = oN;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::OA (int oA) {
  
  if (oA >= 0) this->oA = oA;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::M (bool m) {
  
  this->m = m;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::MR (int mR) {
  
  this->mR = mR;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::MV (bool mV) {
  
  this->mV = mV;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::Patterns (TListE <PatternRecord>* patterns) {
  
  if (patterns) *(this->patterns) = *(patterns);
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void Pratt2Patterns::Matches (TListE <PatternMatches>* matches) {
  
  if (matches) *(this->matches) = *(matches);
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* Pratt2Patterns::Namefile (void) {
  
  return this->namefile;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::Code (void) {
  
  return this->code;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::NumberSeq (void) {
  
  return this->numberSeq;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::CM (void) {
  
  return this->cM;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
double Pratt2Patterns::CPercent (void) {
  
  return this->cPercent;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* Pratt2Patterns::PP (void) {
  
  return this->pP;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::PL (void) {
  
  return this->pL;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::PN (void) {
  
  return this->pN;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::PX (void) {
  
  return this->pX;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::FN (void) {
  
  return this->fN;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::FL (void) {
  
  return this->fL;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::FP (void) {
  
  return this->fP;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool Pratt2Patterns::BI (void) {
  
  return this->bI;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::BN (void) {
  
  return this->bN;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* Pratt2Patterns::S (void) {
  
  return this->s;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* Pratt2Patterns::G (void) {
  
  return this->g;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::E (void) {
  
  return this->e;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool Pratt2Patterns::R (void) {
  
  return this->r;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool Pratt2Patterns::RG (void) {
  
  return this->rG;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* Pratt2Patterns::OF (void) {
  
  return this->oF;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool Pratt2Patterns::OP (void) {
  
  return this->oP;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::ON (void) {
  
  return this->oN;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::OA (void) {
  
  return this->oA;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool Pratt2Patterns::M (void) {
  
  return this->m;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int Pratt2Patterns::MR (void) {
  
  return this->mR;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool Pratt2Patterns::MV (void) {
  
  return this->mV;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
TListE <PatternRecord>* Pratt2Patterns::Patterns (void) {
  
  return this->patterns;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
TListE <PatternMatches>* Pratt2Patterns::Matches (void) {
  
  return this->matches;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool Pratt2Patterns::LoadDataFromFile (void) {
  
  if (!this->namefile || !this->namefile->Length()) 
    return false;
  
  ifstream filepattern (this->namefile->Out());
  
  bool     startPatterns = false;
  bool     startMatches  = false;
  
  if (!filepattern.is_open()) return false;
  
  char   buffer [LENGTHTEXT + 1];
  String stringBuffer;
  
  while (!filepattern.eof()) {
    
    filepattern.getline(buffer, LENGTHTEXT);
    stringBuffer.In(buffer);
    stringBuffer.Trim();
    
    if (!stringBuffer.Length()) continue;
    
    if (stringBuffer.Contain("Analysing")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "Analysing %d sequences from file %*s", &(this->numberSeq));
      continue;
    }
    
    if (stringBuffer.Contain("CM: min Nr of Seqs to Match")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "CM: min Nr of Seqs to Match                %d", &(this->cM));
      continue;
    }
    
    if (stringBuffer.Contain("C%: min Percentage Seqs to Match")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "C%%: min Percentage Seqs to Match          %lf", &(this->cPercent));
      continue;
    }
    
    if (stringBuffer.Contain("PP: pos in seq [off,complete,start]")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "PP: pos in seq [off,complete,start]        %s", buffer);
      this->pP->In(buffer);
      continue;
    }
    
    if (stringBuffer.Contain("PL: max Pattern Length")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "PL: max Pattern Length                      %d", &(this->pL));
      continue;
    }
    
    if (stringBuffer.Contain("PN: max Nr of Pattern Symbols")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "PN: max Nr of Pattern Symbols               %d", &(this->pN));
      continue;
    }
    
    if (stringBuffer.Contain("PX: max Nr of consecutive x's")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "PX: max Nr of consecutive x's                %d", &(this->pX));
      continue;
    }
    
    if (stringBuffer.Contain("FN: max Nr of flexible spacers")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "FN: max Nr of flexible spacers               %d", &(this->fN));
      continue;
    }
    
    if (stringBuffer.Contain("FL: max Flexibility")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "FL: max Flexibility                          %d", &(this->fL));
      continue;
    }
    
    if (stringBuffer.Contain("FP: max Flex.Product")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "FP: max Flex.Product                       %d", &(this->fP));
      continue;
    }
    
    if (stringBuffer.Contain("BI: Input Pattern Symbol File")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "BI: Input Pattern Symbol File              %s", buffer);
      this->bI = (strstr(buffer, "on"))?true:false;
      continue;
    }
    
    if (stringBuffer.Contain("BN: Nr of Pattern Symbols Initial Search")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "BN: Nr of Pattern Symbols Initial Search    %d", &(this->bN));
      continue;
    }
    
    if (stringBuffer.Contain("S: Scoring [info,mdl,tree,dist,ppv]")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "S: Scoring [info,mdl,tree,dist,ppv]       %s", buffer);
      this->s->In(buffer);
      continue;
    }
    
    if (stringBuffer.Contain("G: Pattern Graph from [seq,al,query]")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "G: Pattern Graph from [seq,al,query]       %s", buffer);
      this->g->In(buffer);
      continue;
    }
    
    if (stringBuffer.Contain("E: Search Greediness")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "E: Search Greediness                         %d", &(this->e));
      continue;
    }
    
    if (stringBuffer.Contain("R: Pattern Refinement")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "R: Pattern Refinement                       %s", buffer);
      this->r = (strstr(buffer, "on"))?true:false;
      continue;
    }
    
    if (stringBuffer.Contain("RG: Generalise ambiguous symbols")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "RG: Generalise ambiguous symbols            %s", buffer);
      this->rG = (strstr(buffer, "on"))?true:false;
      continue;
    }
    
    if (stringBuffer.Contain("OF: Output Filename")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "OF: Output Filename                     %s", buffer);
      this->oF->In(buffer);
      continue;
    }
    
    if (stringBuffer.Contain("OP: PROSITE Pattern Format")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "OP: PROSITE Pattern Format                  %s", buffer);
      this->oP = (strstr(buffer, "on"))?true:false;
      continue;
    }
    
    if (stringBuffer.Contain("ON: max number patterns")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "ON: max number patterns                   %d", &(this->oN));
      continue;
    }
    
    if (stringBuffer.Contain("OA: max number Alignments")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "OA: max number Alignments                    %d", &(this->oA));
      continue;
    }
    
    if (stringBuffer.Contain("M: Print Patterns in sequences")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "M: Print Patterns in sequences              %s", buffer);
      this->m = (strstr(buffer, "on"))?true:false;
      continue;
    }
    
    if (stringBuffer.Contain("MR: ratio for printing")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "MR: ratio for printing                      %d", &(this->mR));
      continue;
    }
    
    if (stringBuffer.Contain("MV: print vertically")) {
      stringBuffer.ITrim();
      sscanf(stringBuffer.Out(), "MV: print vertically                       %s", buffer);
      this->mV = (strstr(buffer, "on"))?true:false;
      continue;
    }
    
    if (stringBuffer.Contain("No patterns found")) break;
    
    if (stringBuffer.Contain("Best Patterns (after refinement phase):")) {
      
      startPatterns = true;
      
      filepattern.getline(buffer, LENGTHTEXT);
      stringBuffer.In(buffer);
      stringBuffer.Trim();

      continue;
      
    }
    
    if (stringBuffer.Contain("Best patterns with alignments:")) startPatterns = false;
    
    if (startPatterns) {
      
      String stringPart;
      char*  parts = strtok(buffer, ":");
      
      if (!parts) continue;
      
      parts = strtok(NULL, ":");
      if (!parts) continue;
      
      stringPart.In(parts);
      stringPart.ITrim();
      
      PatternRecord* newPatternRecord = new PatternRecord ();
      double         fitness = 0;
      int            hits    = 0, seqs = 0; 
      
      if (!newPatternRecord) continue;
      
      newPatternRecord->ParamCode(this->code);
      
      sscanf(stringPart.Out(), "%lf %d(%d) %s", &fitness, &hits, &seqs, parts);
      newPatternRecord->Pattern()->In(parts);
      
      newPatternRecord->Fitness(fitness);
      newPatternRecord->Hits(hits);
      newPatternRecord->Seq(seqs);
      
      if (newPatternRecord) this->patterns->Add(newPatternRecord);
      
      continue;
      
    }
    
    if (stringBuffer.Contain("PATTERN MATCHES:")) { 
      
      startMatches = true; 
      
      while (!filepattern.eof() && !(strstr(buffer, "---"))) {
        filepattern.getline(buffer, LENGTHTEXT);
        stringBuffer.In(buffer);
        stringBuffer.Trim();
        if (!stringBuffer.Length()) continue;
      }
      
      continue;
    
    }
    
    if (startMatches) {
      
      if (strstr(buffer, "---")) break;
      
      char*  parts  = strtok(buffer, ": ");
      if (!parts)  continue;
      char*  parts1 = strtok(NULL, ": ");
      if (!parts1) continue;
      
      PatternMatches* newPatternMatches = new PatternMatches (this->code, parts, parts1);
      if (newPatternMatches) this->matches->Add(newPatternMatches);
      
      continue;
      
    }
    
  }
  
  filepattern.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* Pratt2Patterns::ToStringParameters (void) {
  
  this->toString->In("");
  
  char buffer [LENGTHTEXT + 1];

  //Code:%d #Seqs:%d CM:%d C%%:%f PP:%s PL:%d PN:%d PX:%d FN:%d FL:%d FP:%d BI:%d BN:%d S:%s G:%s E:%d R:%d RG:%d OF:%s OP:%d ON:%d OA:%d M:%d MR:%d MV:%d
    
  sprintf(buffer, "Code:%d #Seqs:%d CM:%d C%%:%f PP:%s PL:%d PN:%d PX:%d FN:%d FL:%d FP:%d BI:%d BN:%d S:%s G:%s E:%d R:%d RG:%d OF:%s OP:%d ON:%d OA:%d M:%d MR:%d MV:%d\0", 
                  this->code,
                  this->numberSeq,
                  this->cM,
                  this->cPercent,
                  this->pP->Out(),
                  this->pL,
                  this->pN,
                  this->pX,
                  this->fN,
                  this->fL,
                  this->fP,
                  (int)this->bI,
                  this->bN,
                  this->s->Out(),
                  this->g->Out(),
                  this->e,
                  (int)this->r,
                  (int)this->rG,
                  this->oF->Out(),
                  (int)this->oP,
                  this->oN,
                  this->oA,
                  (int)this->m,
                  this->mR,
                  (int)this->mV);
    
  this->toString->In(buffer);
  
  return this->toString;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
Pratt2Patterns Pratt2Patterns::operator= (const Pratt2Patterns& pratt2Patterns) {
  
  this->namefile->In(pratt2Patterns.namefile);

  this->code        = pratt2Patterns.code;
  this->numberSeq   = pratt2Patterns.numberSeq;

  this->cM          = pratt2Patterns.cM;
  this->cPercent    = pratt2Patterns.cPercent;

  this->pP->In(pratt2Patterns.pP);
  this->pL          = pratt2Patterns.pL;
  this->pN          = pratt2Patterns.pN;
  this->pX          = pratt2Patterns.pX;
  this->fN          = pratt2Patterns.fN;
  this->fL          = pratt2Patterns.fL;
  this->fP          = pratt2Patterns.fP;
  this->bI          = pratt2Patterns.bI;
  this->bN          = pratt2Patterns.bN;

  this->s->In(pratt2Patterns.s);

  this->g->In(pratt2Patterns.g);
  this->e           = pratt2Patterns.e;
  this->r           = pratt2Patterns.r;
  this->rG          = pratt2Patterns.rG;

  this->oF->In(pratt2Patterns.oF);
  this->oP          = pratt2Patterns.oP;
  this->oN          = pratt2Patterns.oN;
  this->oA          = pratt2Patterns.oA;
  this->m           = pratt2Patterns.m;
  this->mR          = pratt2Patterns.mR;
  this->mV          = pratt2Patterns.mV;

  *(this->patterns) = *(pratt2Patterns.patterns);
  *(this->matches)  = *(pratt2Patterns.matches);
    
  return *this;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
